<?php
 add_action("admin_init", "wpbl_init");
function wpbl_init(){
  add_meta_box("bookid-meta", "Book ID", "bookid", "library", "normal", "high");
  add_meta_box("details-meta", "Details Info", "details", "library", "normal", "low");
}
 
function bookid(){
  global $post;
  $custom = get_post_custom($post->ID);
  $bookid = $custom["bookid"][0];
  ?><p>
  <label>Book ID:</label>
   <input type="text" cols="30" rows="1" name="bookid" value="<?php echo $bookid; ?>" /></p>
  <?php
}
function details() {
  global $post,$wpdb;
  $custom = get_post_custom($post->ID);
  $from = $custom["from"][0];
  $price = $custom["price"][0];
  $copies = $custom["copies"][0];
  $pub_year = $custom["pub_year"][0];
  $receive_date = $custom["receive_date"][0];

$args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'names');
$list_dates = wp_get_object_terms($post->ID, 'dates', $args);
 wp_set_object_terms( $post_id, $list_date, 'dates' );
 $date=$list_dates[0];
 if($date==''){
 $list_date=get_the_time('j, M, Y', $post->ID);
 }else{
 $list_date=$list_dates[0];
 }
 
  ?>
  <p><label>Received From:</label><br />
  <input type="text" cols="30" rows="1" name="from" id="from" value="<?php echo $from; ?>" /></p>
  <p><label>Received Date:</label><br />
  <input type="text" cols="30" rows="1" name="receive_date" value="<?php echo $receive_date; ?>" /></p>
  <p><label>Listed Date:</label><br />
  <input type="text" cols="30" rows="1" name="dates" id="dates"  value="<?php echo $list_date; ?>" /></p>
  <p><label>Price:</label><br />
  <input type="text" cols="30" rows="1" name="price" value="<?php echo $price; ?>" /></p>
   <p><label>No. of Books:</label><br />
  <input type="text" cols="30" rows="1" name="copies" value="<?php echo $copies; ?>" /></p>
     <p><label>Published Year:</label><br />
  <input type="text" cols="30" rows="1" name="pub_year" value="<?php echo $pub_year; ?>" /></p>
  <?php
}
add_action('save_post', 'save_details');
function save_details(){
  global $post;
 
  update_post_meta($post->ID, "bookid", $_POST["bookid"]);
  update_post_meta($post->ID, "receive_date", $_POST["receive_date"]);
  update_post_meta($post->ID, "from", $_POST["from"]);
  update_post_meta($post->ID, "price", $_POST["price"]);
  update_post_meta($post->ID, "copies", $_POST["copies"]);
  update_post_meta($post->ID, "pub_year", $_POST["pub_year"]);
   update_post_meta($post->ID, "authors", $_POST["authors"]);
  update_post_meta($post->ID, "editions", $_POST["editions"]);
  update_post_meta($post->ID, "publishers", $_POST["pblishers"]);
  update_post_meta($post->ID, "classcat", $_POST["classcat"]);
  update_post_meta($post->ID, "dates", $_POST["dates"]);
}
?>